
		// 动态加载js脚本
		function loadJS( url, callback ){
		    var script = document.createElement('script'),
		        fn = callback || function(){};
		    script.type = 'text/javascript';
		    
		    //IE
		    if(script.readyState){
		        script.onreadystatechange = function(){
		            if( script.readyState == 'loaded' || script.readyState == 'complete' ){
		                script.onreadystatechange = null;
		                fn();
		            }
		        };
		    }else{
		        //其他浏览器
		        script.onload = function(){
		            fn();
		        };
		    }
		    script.src = url;
		    document.getElementsByTagName('head')[0].appendChild(script);
		}

		//登录验证
		function validateform() {
		
			var userName = $.trim($("#userName").val());
			var password = $.trim($("#password").val());
			var flg = true;
			if (userName == "") {
				$("#replyParamId").html("用户名不能为空！");
				$("#userName").focus();
				return;
			}
			if (password == "") {
				$("#replyParamId").html("密码不能为空！");
				$("#password").focus();
				return;
			}
			var veriCode;
			if($("#veriCode").length > 0){
				veriCode = $.trim($("#veriCode").val());
				if (veriCode == "") {
					$("#replyParamId").html("验证码不能为空！");
					$("#veriCode").focus();
					return;
				}
			}
			//写cookies
			setCookie("USER_NAME", name);
			
			var fromFile = createFrom("login.action");
			loadFrom("userName", userName, fromFile);
			loadFrom("password", password, fromFile);
			if(typeof(veriCode)!="undefined"){
				loadFrom("veriCode", veriCode, fromFile);
			}
			fromFile.submit();
		}
		
		//写cookies
		function setCookie(name, value){ 
		 	var Days = 30; 
		 	var exp = new Date(); 
		 	exp.setTime(exp.getTime() + Days*24*60*60*1000); 
		 	document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString(); 
		}
		
		//读取cookies 
		function getCookie(name){
		 	var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");		 
		 	if(arr=document.cookie.match(reg)){
		  		return unescape(arr[2]);
		 	}else{
		  		return null;
		 	} 
		}
		
		function reset() {
			$("#userName").val('');
			$("#password").val('');
			$("#veriCode").val('');
		}
		
		function changeValidateCode() {
			//每次请求需要一个不同的参数，否则可能会返回同样的验证码 
			var url = "rand.action?par=" + new Date().getTime();
			$('#img').attr("src",url);
		}
		
		function keyLogin() {
			if (event.keyCode == 13) {
				validateform();
			}
		}
